Skip to main content

All Questions

Tagged with
0votes
4answers
120views

Why does this code write the answers more than once instead of just once?

I've just made a C program about finding perfect numbers. It is kinda working, but it writes out the answers more than once(and it writes 24 as well for some reason). I have very basic C knowledge, I ...
Bence Kostyál-Szilágyi's user avatar
1vote
2answers
74views

C language pattern with unexpected result

I am trying to create a program in C to draw this pattern : 1 1 2 1 3 1 1 2 2 2 3 2 1 3 2 3 3 3 1 4 2 4 3 4 1 5 2 5 3 5 I checked the answer from solutions. #include <stdio.h> int main () { ...
Fady Saad's user avatar
2votes
1answer
34views

Modification pgm fill 2-D Array using a pointer and it doesn't work

Initial pgm void assign( int **mat, int n, int m ) { int **p = mat; int **p_end = p + n; for ( ; p < p_end; ++p ) { int *q = *p; int *q_end = q + m; for ( ; q < q_end; ++q ) { printf( ...
hogar's user avatar
0votes
1answer
53views

Nested strtok() calls to tokenize given string does not work as expected [duplicate]

I want to tokenize a provided input string using strtok(). In the first step, I want to tokenize the given string by "|" symbol. Then, I tokenize each substring by ";". Finally, I ...
Devon's user avatar
0votes
0answers
62views

Nested loop to access each record index

I have a text file that has 4 records and each record consists of 4 values. I also have 3D matrix where each item in this matrix is one of those records. I want to iterate over this matrix and get for ...
moonlight's user avatar
2votes
4answers
356views

Print numbers of a matrix in a wave pattern

I want the output to be 7 4 1 2 5 8 9 6 3 but it's coming out to be 1 4 7 2 5 8 3 6 9. How can I fix it, and what's the logic behind it so that I can print the reverse wave pattern, too? #include<...
Samarth Talreja's user avatar
1vote
3answers
130views

for loop in between if statement is not working in C

#include <stdio.h> int main() { int row, col, i, j; char ch; printf("Enter the Value of Row or Column: "); scanf("%d", &row); col = row; int mat[...
MJ Saif's user avatar
0votes
3answers
59views

error in comparing elements of a 2d array using if-else statements

i tried to make a game using 2d character arrays. but the if else statements are not working and the loop is not breaking. Also when i assign a character to the last element of my row , the next row's ...
Mayank's user avatar
1vote
3answers
72views

How do I prevent checking of duplicate elements in a array?

I am checking frequency of each element in an array. The problem is the duplicate elements are counting themselves more than needed, I want to skip the counting procedure of the element which has been ...
NORAGAMI's user avatar
0votes
2answers
115views

Else statement logic is wacko

#include <cs50.h> #include <stdio.h> #include <string.h> #include <ctype.h> int main(void) { string key_upper = "YTNSHKVEFXRBAUQZCLWDMIPGJO"; string key_lower =...
Kalle's user avatar
0votes
2answers
181views

Why do I get a segmentation fault? The code works fine in CLion and VSC

I am currently using exercism, to improve my programming skills. The code works fine in my IDE, but causes an error message on the website. What did I do wrong and how would you improve my code? Thx ...
BenG's user avatar
-3votes
2answers
110views

Stuck on pset 3 (Runoff) HELPP

Can someone tell me why my code doesn't work. here's its description https://cs50.harvard.edu/x/2020/psets/3/runoff/. the error is most probably outside of the main function. edit - the issue has been ...
Hashim's user avatar
1vote
3answers
1kviews

How to use pointers in LeetCode Two Sum problem in C

I am new to LeetCode and my only background in C is a single class of its basics. I wish to improve and learn more. I think my problem here is with the pointers or malloc. How can I solve this? This ...
Leodero20's user avatar
2votes
4answers
141views

How to exit an outer loop in C (without ++)?

In Java, it is possible to escape from an outer loop using such a construct: int[][] matrix; int value; ... outer: { for(int i=0; i<n; i++) for (int j=0; j<m; j++) if (matrix[i][j] ==...
Alexander Gromov's user avatar
1vote
1answer
550views

CS50 plurality, printing winner

bool vote(string name) { // TODO for (int i = 0; i < candidate_count; i++) { if (strcmp(candidates[i].name, name) == 0) //W's { candidates[i].votes++; ...
JamieForster's user avatar

153050per page
close